import json
from datetime import datetime

from django.test import TestCase
from django.test.client import Client

from blog.models import Post
from django.contrib.auth.models import User

class SimpleTest(TestCase):
    def setUp(self):
        self.user = User.objects.create(username="maicki")
        self.date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        Post.objects.create(
            author=self.user,
            title="Testtitle",
            text="Testtext",
            date=self.date
        )
        self.client = Client()

    def testIfCorrectJsonResponse(self):
        response = self.client.get("/blog/json/?post_title=Test").content
        expected = """[{"pk": 1, "model": "blog.post", "fields": {"date": "%s", "text": "Testtext", "title": "Testtitle", "author": 1}}]""" % (self.date, )
        self.assertEquals(response, expected)
